<template>
  <div class="app-container" v-loading.fullscreen.lock="fullLoading">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="120px">
      <el-form-item label="学号" prop="stuNo">
        <el-input v-model="queryParams.stuNo" placeholder="请输入学号" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="姓名" prop="stuName">
        <el-input v-model="queryParams.stuName" placeholder="请输入学生姓名" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>

      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button type="success" plain icon="el-icon-edit" size="mini" @click="manyProcess">一键通过</el-button>
      </el-col>

      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="auditDetailsList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <!-- <el-table-column label="学院" align="center" prop="deptName"  width="110"/> -->
      <!-- <el-table-column label="专业" align="center" prop="majorsName" width="200"/> -->
      <el-table-column label="班级" align="center" prop="className" width="270" />
      <el-table-column label="学生姓名" align="center" prop="submitterName" />
      <el-table-column label="学号" align="center" prop="stuNo" />
      <!-- <el-table-column label="项目大类" align="center" prop="rules.ruleName" /> -->
      <el-table-column label="项目名称" align="center" prop="projectName" width="250" />
      <el-table-column label="提交时间" align="center" prop="createTime" width="250" />
      <el-table-column label="审核状态" align="center" prop="statusCode">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.audius_detail_type" :value="scope.row.statusCode" />
        </template>
      </el-table-column>
      <!-- <el-table-column label="备注" align="center" prop="remarks" /> -->
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width" width="150">
        <template slot-scope="scope">
          <el-button size="mini" type="text" icon="el-icon-folder" @click="processVClick(scope.row)">审核</el-button>

          <el-button size="mini" type="text" icon="el-icon-edit" @click="handleUpdate(scope.row)"
            v-hasPermi="['comprehensive:auditDetails:edit']">修改</el-button>
          <el-button size="mini" type="text" icon="el-icon-delete" @click="handleDelete(scope.row)"
            v-hasPermi="['comprehensive:auditDetails:remove']">删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize"
      @pagination="getList" />

    <!-- 添加或修改审核明细对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="项目名称" prop="projectName">
          <el-input v-model="form.projectName" placeholder="请输入项目名称" />
        </el-form-item>
        <el-form-item label="提交人" prop="submitterName">
          <el-input v-model="form.submitterName" placeholder="请输入提交人" />
        </el-form-item>
        <el-form-item label="项目名称" prop="projectName">
          <el-input v-model="form.projectTypeId" placeholder="请输入项目类型id" />
        </el-form-item>
        <el-form-item label="审核状态" prop="statusCode">
          <el-select v-model="form.statusCode" placeholder="请选择审核状态">
            <el-option v-for="dict in dict.type.audius_detail_type" :key="dict.value" :label="dict.label"
              :value="parseInt(dict.value)"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="备注" prop="remarks">
          <el-input v-model="form.remarks" placeholder="请输入备注" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>

    <el-dialog style="margin-top: 0;" title="审核" :visible.sync="processV" append-to-body>
      <el-form>
        <el-form-item label="是否通过">
          <el-row>
            <el-col :span="12">
              <el-radio-group v-model="processStatus">
                <el-radio :label="10">驳回</el-radio>
                <el-radio :label="6" v-if="processForm.statusCode == 1">通过</el-radio>
                <el-radio :label="6" v-else>通过</el-radio>
                <el-radio :label="11">拒绝</el-radio>
              </el-radio-group>
            </el-col>
            <el-col :span="4">
              <el-button type="primary" @click="doProcess">确 定</el-button>
            </el-col>
          </el-row>

        </el-form-item>

        <el-form-item label="未通过理由" v-if="processStatus != 6">
          <el-input v-model="processForm.remarks" type="textarea"></el-input>
        </el-form-item>

      </el-form>

      <el-form label-width="100px">
        <el-form-item label="学院" prop="projectName">
          <el-input v-model="detailInfo.student.dept.deptName" readonly />
        </el-form-item>
        <el-form-item label="专业" prop="projectName">
          <el-input v-model="detailInfo.student.srsMajors.majorName" readonly />
        </el-form-item>
        <el-form-item label="班级" prop="projectName">
          <el-input v-model="detailInfo.student.srsClass.className" readonly />
        </el-form-item>

        <el-form-item label="项目名称" prop="projectName">
          <el-input v-model="detailInfo.rules.ruleName" readonly />
        </el-form-item>

        <el-form-item label="加分学生" prop="submitterName">
          <el-input v-model="detailInfo.student.name" readonly />
        </el-form-item>
        <el-form-item label="描述" prop="submitterName">
          <el-input v-model="detailInfo.description" type="textarea" readonly />
        </el-form-item>
      </el-form>
      <el-carousel indicator-position="outside">
        <el-carousel-item v-for="(v, i) in material_list" :key="i" style="text-align: center;">
          <image-preview :src="v" :width="400" :height="300" />
          <!-- <el-image :src="getImg(v)" style="height: 100%;"></el-image> -->
        </el-carousel-item>
      </el-carousel>
      <div slot="footer" class="dialog-footer">
      </div>
    </el-dialog>
  </div>
</template>
  
<script>
import { getAuditDetails, delAuditDetails, addAuditDetails, updateAuditDetails, myReview, process as doProcess, manyProcess, getDetailInfo } from "@/api/stuCQS/process-center/auditDetails";
import { isEmpty,fullLoading } from "@/api/helpFunc";

import { listRules } from "@/api/stuCQS/basedata/cphRules";
import { listGrade } from "@/api/stuCQS/basedata/grade";


export default {
  name: "AuditDetails",
  dicts: ['audius_detail_type'],
  data() {
    return {
      fullLoading: false,

      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 审核明细表格数据
      auditDetailsList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        projectName: null,
        submitterId: null,
        submitterName: null,
        reviewedById: null,
        projectId: null,
        projectTypeId: null,
        statusCode: null,
        remarks: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        createTime: [
          { required: true, message: "创建时间不能为空", trigger: "blur" }
        ],
      },

      processV: false,
      processForm: {},
      processStatus: 10,

      //审核时查看的详细信息
      detailInfo: {
        rules: {},
        student: {
          dept: {},
          srsClass: {},
          srsMajors: {}
        }
      },

      //附件
      material_list: [],

      //搜索框
      //年级
      grade_list: [],
      //项目类型
      type_list: []

    };
  },
  created() {
    this.getList();
    this.getGradeList();
    this.getTypeList();
  },
  methods: {

    async getTypeList() {
      let res = await listRules();
      this.type_list = [...res.data];
    },

    async getGradeList() {
      let res = await listGrade();
      this.grade_list = [...res.rows];
    },

    //获取图片
    getImg(src) {
      return process.env.VUE_APP_BASE_API + src
    },

    //批量审核
    async manyProcess() {
      if (this.ids.length == 0) {
        this.$message.info("请先选择");
      } else {
        let loading = fullLoading(this);
        let res = await manyProcess(this.ids);
        loading.close();
        if (res.code == 200) {
          this.$message.success(res.msg);
          this.getList();
        }
      }

    },

    //审核
    async doProcess() {
      let sdata = { ...this.processForm };
      sdata.statusCode = this.processStatus;
      if (this.processStatus != 6 && isEmpty(sdata.remarks)) {
        this.$message.info("请填写未通过原因");
        return;
      }
      this.fullLoading = true;
      let res = await doProcess(sdata);
      this.fullLoading = false;
      this.$message.info(res.msg);
      this.processV = false;
      this.getList();
    },

    async processVClick(val) {
      let id = val.id;
      let res = await getDetailInfo(id);
      if (!isEmpty(res.data)) {
        this.detailInfo = { ...res.data };
        if (!isEmpty(this.detailInfo.material)) {
          this.material_list = this.detailInfo.material.split(",");
        }
      }
      this.processStatus = 10;
      this.processForm = val;
      this.processV = true;
    },


    /** 查询审核明细列表 */
    getList() {
      this.loading = true;
      myReview(this.queryParams).then(response => {
        this.auditDetailsList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        projectName: null,
        submitterId: null,
        submitterName: null,
        reviewedById: null,
        projectId: null,
        projectTypeId: null,
        statusCode: null,
        createTime: null,
        remarks: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length !== 1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加审核明细";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getAuditDetails(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改审核明细";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateAuditDetails(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addAuditDetails(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除审核明细编号为"' + ids + '"的数据项？').then(function () {
        return delAuditDetails(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => { });
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('comprehensive/auditDetails/export', {
        ...this.queryParams
      }, `auditDetails_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
<style scoped>
.el-carousel__item h3 {
  color: #475669;
  font-size: 18px;
  opacity: 0.75;
  line-height: 300px;
  margin: 0;
}

.el-carousel__item:nth-child(2n) {
  background-color: #99a9bf;
}

.el-carousel__item:nth-child(2n+1) {
  background-color: #d3dce6;
}
</style>